home *** CD-ROM | disk | FTP | other *** search
- #include "DialogUtils.h"
-
-
- /* By Ingemar Ragnemalm 1993-1995 */
- /* This file holds some selected calls from my Dialog Utility file,*/
- /* translated to C */
-
- /* This is yet another unit with small routines for making dialog management
- a bit easier. The big difference to all others I've seen is that this one
- does some error checking, verifying that whatever it is doing something to
- is an item to which you are allowed to do it. This saves *lots* of crashes! */
-
-
-
- /*Set the text of a StatText/EditText*/
-
- void SetTextDItem(DialogPtr theDialog, short itemNumber, Str255 theString)
- {
- short itemKind;
- ControlHandle itemHandle;
- Rect itemBox;
-
- GetDialogItem(theDialog, itemNumber, &itemKind, (Handle *)&itemHandle, &itemBox);
-
- /*Check if the itemKind says that it is the right kind of item! IMPORTANT!*/
- itemKind = itemKind & 127;
-
- switch ( itemKind )
- {
- case 8:
- case 16: /*statText, editText*/
- SetDialogItemText((Handle)itemHandle, theString); break;
- case 0:
- case 1:
- case 2:
- case 4:
- case 5:
- case 6: /*button, checkbox, radio - but what is 4?*/
- SetControlTitle(itemHandle, theString); break;
- default: /*Other items have no text to set*/
- SysBeep(1);
- }/*case*/
- } /*SetTextDItem*/
-
-
- /*Text from StatText/EditText*/
- void GetTextDItem(DialogPtr theDialog, short itemNumber, Str255 theString)
- {
- short itemKind;
- ControlHandle itemHandle;
- Rect itemBox;
-
- GetDialogItem(theDialog, itemNumber, &itemKind, (Handle *)&itemHandle, &itemBox);
-
- /*Check if the itemKind says that it is the right kind of item! IMPORTANT!*/
- itemKind = itemKind & 127;
-
- theString[0] = 0; /*Set to empty string as default*/
- switch ( itemKind )
- {
- case 8:
- case 16: /*statText, editText*/
- GetDialogItemText((Handle)itemHandle, theString); break;
- case 0:
- case 1:
- case 2:
- case 4:
- case 5:
- case 6: /*button, checkbox, radio - but what is 4?*/
- GetControlTitle(itemHandle, theString); break;
- default: /*Other items have no text to set*/
- SysBeep(1);
- }/*case*/
- } /*GetTextDItem*/
-
-
- /*Set checkbox/radio*/
-
- void SetBooleanDItem(DialogPtr theDialog, short itemNumber, Boolean theBoolean)
- {
- short itemKind;
- ControlHandle itemHandle;
- Rect itemBox;
-
- GetDialogItem(theDialog, itemNumber, &itemKind, (Handle *)&itemHandle, &itemBox);
-
- /*Check if the itemKind says that it is the right kind of item! IMPORTANT!*/
- itemKind = itemKind & 127;
-
- switch ( itemKind )
- {
- case 8:
- case 16: /*statText, editText*/
- if ( theBoolean )
- SetDialogItemText((Handle)itemHandle, "\ptrue");
- else
- SetDialogItemText((Handle)itemHandle, "\pfalse");
- break;
- case 0:
- case 1:
- case 2:
- case 4:
- case 5:
- case 6: /*button, checkbox, radio - but what is 4?*/
- SetControlValue(itemHandle, (short)theBoolean); break;
- default: /*Other items have no text to set*/
- SysBeep(1);
- }/*case*/
- } /*SetBooleanDItem*/
-
-
- /*Boolean values from checkbox/radio*/
-
- Boolean GetBooleanDItem(DialogPtr theDialog, short itemNumber)
- {
- short itemKind;
- ControlHandle itemHandle;
- Rect itemBox;
-
- GetDialogItem(theDialog, itemNumber, &itemKind, (Handle *)&itemHandle, &itemBox);
-
- /*Check if the itemKind says that it is the right kind of item! IMPORTANT!*/
- itemKind = itemKind & 127;
-
- switch ( itemKind )
- {
- case 0:
- case 1:
- case 2:
- case 4:
- case 5:
- case 6: /*button, checkbox, radio - but what is 4?*/
- return (Boolean)GetControlValue(itemHandle);
- default: /*Others have no value*/
- SysBeep(1);
- };/*case*/
- return false;
- } /*GetBooleanDItem*/
-
- void ToggleBooleanDItem(DialogPtr theDialog, short itemNumber)
- {
- SetBooleanDItem(theDialog, itemNumber, ! GetBooleanDItem(theDialog, itemNumber));
- } /*ToggleBooleanDItem*/
-